# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

import urllib.request
# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class Www58PicPipeline:
    def process_item(self, item, spider):
        a=1
        for i in range(0,len(item['picurl'])):
            thispic = item['picurl'][i]
            trueurl = "http:" + thispic.split('!')[0] + '!w1024_new_small'
            localpath = "D:/data/www.58pic.com/" + str(a) + '.' +item['title'][i].split('<i>')[0] + '.jpg'
            urllib.request.urlretrieve(trueurl,filename=localpath)
            a+=1
        return item
